package edu.towson.cis.cosc490.jdehlinger.lab3;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

public class ToDoListActivity extends Activity implements OnClickListener, OnLongClickListener{
    
	private Button m_addButton;
	private EditText m_editText;
	private String m_toDoItem;
	private LinearLayout m_itemListView;
	private boolean m_darkColor;
	
	
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        initLayout();
    }
    
    //Initializes the Layout
    protected void initLayout(){
    	m_addButton = (Button) this.findViewById(R.id.button1);
        m_editText = (EditText) this.findViewById(R.id.editText1);
        m_itemListView = (LinearLayout) this.findViewById(R.id.toDoListView);
        m_addButton.setOnClickListener(this);
    }
    
    //OnClickListener for big ass button
    public void onClick(View v){
    	//m_toDoItem = m_editText.getText().toString();
    	Intent detailPane = new Intent(v.getContext(), CreateToDoActivity.class);
    	startActivityForResult(detailPane, 0);
    	
    	
    	//addToDoItem();
    }
    
    protected void onActivityResult(int requestCode, int resultCode, Intent data){
    	super.onActivityResult(requestCode, resultCode, data);
    	Bundle returnBundle = data.getExtras();
    	String test = returnBundle.getString("1");
    	
    	
    	Toast.makeText(getApplicationContext(), test, Toast.LENGTH_SHORT).show();
    	
    }
    
    
    
    
    
    
    
    
    
    private void addToDoItem(){
    	ToDoItem newItem = new ToDoItem(m_toDoItem);
    	
    	TextView newItemTextView = new TextView(this);
    	
    	if(this.m_darkColor) {
			newItemTextView.setBackgroundColor(getResources().getColor(R.color.light));
			this.m_darkColor = false;
		}	
		else {
			newItemTextView.setBackgroundColor(getResources().getColor(R.color.dark));
			this.m_darkColor = true;
		}
    	
    	
    	newItemTextView.setText(newItem.getToDoItem());
    	m_itemListView.addView(newItemTextView);
    	newItemTextView.setOnLongClickListener(this);
    	m_editText.setText("");
    }

	//LongPress listener for toDoItems in the itemListView
	public boolean onLongClick(View v) {
		
		TextView tv = (TextView) v;
		String message = tv.getText().toString();

	    Intent smsIntent = new Intent(Intent.ACTION_VIEW);

        smsIntent.putExtra("sms_body", "To-Do List Item: " + message); 
        smsIntent.putExtra("address", "");
        smsIntent.setType("vnd.android-dir/mms-sms");

        startActivity(smsIntent);
        
		return false;
	}
}